package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowDouyinMember;
import cn.stylefeng.guns.modular.manager.mapper.FlowDouyinMemberMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowDouyinMemberParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowDouyinMemberResult;
import  cn.stylefeng.guns.modular.manager.service.FlowDouyinMemberService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 抖音会员 服务实现类
 * </p>
 *
 * @author LeiChen
 * @since 2024-08-22
 */
@Service
public class FlowDouyinMemberServiceImpl extends ServiceImpl<FlowDouyinMemberMapper, FlowDouyinMember> implements FlowDouyinMemberService {

    @Override
    public void add(FlowDouyinMemberParam param){
        FlowDouyinMember entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowDouyinMemberParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowDouyinMemberParam param){
        FlowDouyinMember oldEntity = getOldEntity(param);
        FlowDouyinMember newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowDouyinMemberResult findBySpec(FlowDouyinMemberParam param){
        return null;
    }

    @Override
    public List<FlowDouyinMemberResult> findListBySpec(FlowDouyinMemberParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowDouyinMemberParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowDouyinMemberParam param){
        return param.getMemberId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowDouyinMember getOldEntity(FlowDouyinMemberParam param) {
        return this.getById(getKey(param));
    }

    private FlowDouyinMember getEntity(FlowDouyinMemberParam param) {
        FlowDouyinMember entity = new FlowDouyinMember();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
